package com.gilgamesh.mall.product.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gilgamesh.mall.product.sql.ProductDetailSql;
import com.gilgamesh.mall.sdk.bean.product.ProductDetailEntity;
import com.gilgamesh.mall.sdk.dto.product.ProductDetailDTO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;

/**
 * @author yanm
 * @date 2021/1/13 9:15
 **/
@Mapper
public interface ProductDetailDao extends BaseMapper<ProductDetailEntity> {
    @Results(
            id = "productDetailDTOMap",value = {
            @Result(column = "id" ,jdbcType = JdbcType.BIGINT,javaType = Long.class,property = "id"),
            @Result(column = "sku_code",jdbcType = JdbcType.VARCHAR,javaType = String.class,property = "skuCode"),
            @Result(column = "product_code" ,jdbcType = JdbcType.VARCHAR,javaType = String.class,property = "productCode"),
            @Result(column = "shopping_cart_description",jdbcType = JdbcType.VARCHAR,javaType = String.class,property = "shoppingCartDescription"),
            @Result(column = "create_time",jdbcType = JdbcType.DATETIMEOFFSET,javaType = java.util.Date.class,property = "createTime"),
            @Result(column = "original_price",jdbcType = JdbcType.DECIMAL,javaType = java.math.BigDecimal.class,property = "originalPrice"),
            @Result(column = "current_price",jdbcType = JdbcType.DECIMAL,javaType = java.math.BigDecimal.class,property = "currentPrice"),
    }
    )

    /**
     * 通过主键获取商品DTO
     *
     * @param id 商品id,主键
     * @return 商品dto
     * @author yanm
     * @date 2021/1/13 9:22
     **/
    @Select("select * from t_product_detail where id=#{id}")
    ProductDetailDTO getProductDetailById(Long id);

    /**
     * 高级查询
     *
     * @param entity 商品entity
     * @return 商品DTO列表
     * @author yanm
     * @date 2021/1/13 9:24
     **/
    @SelectProvider(type= ProductDetailSql.class,method="listProductDetails")
    List<ProductDetailDTO> listProductDetails(ProductDetailEntity entity);


    /**
     * t_product_detail·中新增一条记录
     *
     * @param entity 商品详情entity
     * @return 是否插入成功
     * @author yanm
     * @date 2021/1/13 9:29
     **/
    Integer add(ProductDetailEntity entity);

    /**
     * 修改
     *
     * @param entity 商品详情entity
     * @return 是否修改成功
     * @author yanm
     * @date 2021/1/13 9:32
     **/
    Integer update(ProductDetailEntity entity);

}
